﻿Imports Kairyu.DCEngine

''' <summary>
''' 列マップクラス
''' </summary>
''' <remarks></remarks>
Public Class ColumnMap

    Public Sub New(table As TableMap, index As Integer, prop As LiteralProperty)
        If table Is Nothing Then Throw New ArgumentNullException("table")
        If prop Is Nothing Then Throw New ArgumentNullException("prop")

        Me.Table = table
        Me.Index = index
        Me.LiteralProperty = prop

        Me.AliasName = Me.Table.AliasName & "_" & Me.Index
        _columnString = Me.Table.AliasName & "." & Me.LiteralProperty.LiteralName & " " & Me.AliasName
    End Sub

    Private _table As TableMap
    ''' <summary>
    ''' テーブルマップ
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Table As TableMap
        Get
            Return _table
        End Get
        Private Set(value As TableMap)
            _table = value
        End Set
    End Property

    Private _index As Integer
    ''' <summary>
    ''' 列インデックス
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Index As Integer
        Get
            Return _index
        End Get
        Private Set(value As Integer)
            _index = value
        End Set
    End Property

    Private _isRelated As Boolean
    ''' <summary>
    ''' 結合しているかどうか示します
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks>結合している場合、SELECT句には載せません</remarks>
    Public Property IsRelated As Boolean
        Get
            Return _isRelated
        End Get
        Friend Set(value As Boolean)
            _isRelated = value
        End Set
    End Property

    Private _aliasName As String
    ''' <summary>
    ''' 別名を示します
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property AliasName As String
        Get
            Return _aliasName
        End Get
        Private Set(value As String)
            _aliasName = value
        End Set
    End Property

    Private _literalProperty As LiteralProperty
    ''' <summary>
    ''' リテラルプロパティ
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property LiteralProperty As LiteralProperty
        Get
            Return _literalProperty
        End Get
        Private Set(value As LiteralProperty)
            _literalProperty = value
        End Set
    End Property

    Private _columnString As String
    ''' <summary>
    ''' 列テキストに変換します
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function ToColumnString() As String
        Return _columnString
        'Return String.Format("{0}.{1} {2}", Me.Table.AliasName, Me.LiteralProperty.LiteralName, Me.AliasName)
    End Function
End Class